< previous page page_345 next page >

Page 345
Let's illustrate attachments by adding another command button to the form. Set its Name property to cmdAttachTable and its Caption property to Attach Table. Add the code in Listing 9.17 to the cmdAttachTable_Click event.
Type.gifListing 9.17. Coding the cmdAttachTable_Click event.
Private Sub cmdAttachTable_Click()
    '
    ' attach a non-jet table to database
    '
    Dim ws As Workspace
    Dim db As Database
    Dim td As TableDef
    '
    Dim strDBName As String
    Dim strATName As String
    Dim strATDBType As String
    Dim strATDBName As String
    Dim strATSrcName As String
    Dim strMsg As String
    '
    ' init vars
    strDBName = App.Path & "\NewDB.mdb"
    strATName = "FoxProAttachment"
    strATDBName = App.Path
    strATDBType = "FoxPro 2.5;"
    strATSrcName = "Customer.dbf"
    '
    ' call routine to create table
    cmdCreateTable_Click
    '
    ' now open ws & db
    Set ws = DBEngine.Workspaces(0)
    Set db = OpenDatabase(strDBName)
    '
    ' add a new tabldef
    Set td = db.CreateTableDef(strATName)
    '
    ' define the new def as an attachment
    td.Connect = strATDBType & "DATABASE=" & strATDBName
    td.SourceTableName = strATSrcName
    '
    ' append attachment to collection
    db.TableDefs.Append td
    '
    ' show list of tables
    strMsg = ""
    For Each td In db.TableDefs
        strMsg = strMsg & td.Name & vbCrLf
    Next
continues

 
< previous page page_345 next page >

If you like this book, buy it!